package com.创建型模型.E原型模式;

import java.util.Date;

/**
 * @author zhangjiawen
 * @Date: 2022/6/1 16:52
 */
public class ShenCopy  implements Cloneable{

    private String name;

    private Date date;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        //克隆没一个元素
        ShenCopy clone = (ShenCopy)super.clone();

        clone.date=(Date) this.date.clone();


        return clone;
    }

    public ShenCopy() {

    }

    public ShenCopy(String name, Date date) {
        this.name = name;
        this.date = date;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    @Override
    public String toString() {
        return "QianCopy{" +
                "name='" + name + '\'' +
                ", date=" + date +
                '}';
    }

    public static void main(String[] args) throws CloneNotSupportedException {
        Date date=new Date();
        ShenCopy shenCopy=new ShenCopy("原创",date);
        ShenCopy clone = (ShenCopy)shenCopy.clone();

        System.out.println(shenCopy);
        System.out.println(clone);
        System.out.println("=========================");

        date.setTime(22131231);
        System.out.println(shenCopy);
        System.out.println(clone);


    }
}
